<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('出资人缴款') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true" :rules="queryRules">
      <el-form-item :label="$t('缴款时间')">
        <DatePicker
          v-model="dateRange"
          type="daterange"
        />
      </el-form-item>

      <el-form-item :label="$t('Call款期次')" prop="callPeriodName">
        <el-input v-model="queryParams.callPeriodName" :placeholder="$t('Call款期次')" @keyup.enter.native="queryHandle" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t("搜索") }}</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="fundLpPaymentList" border>
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column v-if="queryParams.lpId === undefined" :label="$t('出资人')" align="center" prop="investorName" min-width="200" :show-overflow-tooltip="true" />
      <el-table-column v-if="queryParams.lpId !== undefined" :label="$t('基金名称')" align="center" prop="fundName" min-width="200" :show-overflow-tooltip="true" />
      <el-table-column :label="$t('Call款期次')" align="center" prop="callPeriodName" show-overflow-tooltip min-width="120" />
      <el-table-column :label="$t('缴款时间')" align="center" prop="payDate" show-overflow-tooltip min-width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.payDate) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('缴款金额') + $t('金额单位')" align="center" prop="payMoney" show-overflow-tooltip min-width="120">
        <template slot-scope="scope">
          <span>{{ moneyFormat(scope.row.payMoney, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('操作')" fixed="right" align="center" class-name="small-padding fixed-width" width="200">
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['fund:lppayment:edit']"
            size="small"
            type="text"
            :icon="queryParams.lpId !== undefined ? 'el-icon-view' : 'el-icon-edit'"
            @click="updateHandle(scope.row)"
          >{{ queryParams.lpId === undefined ? $t('修改'): $t('查看') }}</el-button>
          <el-button
            v-show="queryParams.lpId === undefined"
            v-hasPermi="['fund:lppayment:remove']"
            size="small"
            type="text"
            icon="el-icon-delete"
            @click="deleteHandle(scope.row)"
          >{{ $t('删除') }}</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改出资人缴款对话框 -->
    <el-dialog :title="title" :visible.sync="fundLpPaymentLoading" :destroy-on-close="true" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <fundLpPaymentForm ref="fundLpPaymentForm" :other-btn-hide="otherBtnHide" />
    </el-dialog>

  </div>
</template>

<script>
import { listFundLpPayment, delFundLpPayment } from '@/api/fund/lpPayment/fundLpPayment'
import fundLpPaymentForm from './fundLpPaymentForm.vue'
export default {
  components: {
    fundLpPaymentForm
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 出资人缴款表格数据
      fundLpPaymentList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      fundLpPaymentLoading: false,
      otherBtnHide: false,
      // 查询参数
      queryParams: {
          investId: undefined,
          payDate: undefined,
          lpId: undefined,
          investorName: undefined,
          callPeriodName: undefined,
          fundId: this.$route.query.id ? this.$route.query.id : undefined,
          pageNum: 1,
          pageSize: 10
      },
      queryRules: {},
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      // 时间区间
      dateRange: [],
      // 出资人下拉
      investOptions: []
    }
  },
  created() {
  },
  methods: {
    /** 查询出资人缴款列表 */
    getList(data) {
      if (data !== undefined && data !== null && data.lpId !== undefined && data.lpId !== '') {
          this.queryParams.lpId = data.lpId
          this.queryParams.fundId = data.fundId
          this.otherBtnHide = true
      }
      this.loading = true
      listFundLpPayment(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.fundLpPaymentList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    investNameFormat(row) {
      return this.selectDictLabel(this.investOptions, row.investId)
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        fundId: undefined,
        investId: undefined,
        subscriptionAmount: undefined,
        payDate: undefined,
        payMoney: undefined,
        callPeriod: undefined,
        callMoney: undefined,
        remark: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
        delFlag: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.dateRange = []
      this.queryHandle()
    },
    /** 修改按钮操作 */
    updateHandle(row) {
      this.fundLpPaymentLoading = true
      this.title = this.$t('修改出资人缴款')
      this.$nextTick(() => {
        // 调用form页面的 init 方法初始化数据
        this.$refs.fundLpPaymentForm.init(row)
      })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
      this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
        confirmButtonText: this.$t('确定'),
        cancelButtonText: this.$t('取消'),
        type: 'warning'
      }).then(function() {
        return delFundLpPayment(row.id)
      }).then(() => {
        this.getList()
        this.msgSuccess(this.$t('删除成功'))
      }).catch(function() {
      })
    }
  }
}
</script>
